package pers.jason.wppm.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import pers.jason.wppm.api.entity.system.Menu;
import pers.jason.wppm.api.entity.system.SystemManager;
import pers.jason.wppm.api.entity.system.SystemTheme;
import pers.jason.wppm.web.service.MenuService;
import pers.jason.wppm.web.service.SystemService;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class PageController {

    @Autowired
    private MenuService menuService;

    @Autowired
    private SystemService systemService;

    @GetMapping("index")
    public String index(HttpServletRequest request) {
        List<Menu> menus = menuService.getSystemMenu();
        SystemManager systemManager = systemService.getLatestSystem();
        List<SystemTheme> themes = systemService.getThemeByVersion(systemManager.getVersion());
        request.setAttribute("sys_menu_list", menus);
        request.setAttribute("system_manager", systemManager);
        request.setAttribute("system_themes", themes);
        return "index";
    }

}
